<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>权限审核</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="qczlm/css/Pager.css" rel="stylesheet">
    <link href="admin/css/animate.css" rel="stylesheet">
    <script src="qczlm/js/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="qczlm/js/jquery.pager.js" type="text/javascript"></script>
    <link href="admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
</head>
<body class="gray-bg">
	<div style="margin: 6 0 6 0;padding-left:15px;">
		搜索：<select id="op">
				<option value="1">权限</option>
				<option value="2">申请人</option>
			</select>
			<input type="text" id="search" style="outline:none;">
	</div>
	<div class="wrapper wrapper-content animated fadeInRight" id="tTab" style="display:none;">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <table class="table" id="tab" >
                            <tr>
                                <th>编号</th>
                                <th>分平台名称</th>
								<th>申请人</th>
								<th>申请时间</th>
								<th>权限名称</th>
								<th>关键字</th>
								<th>审核状态</th>
                            </tr>
                    </table>
                </div>
            </div>
    </div>
	<div id="tsdiv" style="display:none;">暂时没有数据！</div>
	<div id="pager" style="padding-left:35%;"></div>
	
	<!-- js代码 -->
	<script type="text/javascript" language="javascript">
		var search;
		var type = $('#op').val();
    	PageClick = function(pageclickednumber) {
   			var	page=pageclickednumber;
    		var	pnum=10;
   			$.ajax({
             	url: "mexamine/chlist",
   				type: "post",
            	dataType:"json",
             	data:{page:page,pnum:pnum,search:search,type:type},
            	success:function(data){
            		$("#tTab").show();
            		$("#pager").show();
            		$("#tsdiv").hide();
            		$("#tab").find("tr").nextAll().remove();
            		var json = eval("("+data+")");
            		var num = json[json.length-1];
            		var content = json.splice(0,json.length-1);
					var sumpage = Math.ceil(num/pnum);
            		$("#pager").pager({ pagenumber: pageclickednumber, pagecount: sumpage , buttonClickCallback: PageClick });
            		var status; //状态
					var strHtml; // 文本内容
            		var username; //申请人
            		var appname; //分平台名称
            		for(var i = 0;i<content.length;i++){
            			for(var j = 0;j<content[i].length;j++){
            				for(var k = 0; k <content[i].length;k++){
            					if(k>0){
	            					username=content[i][1];
		            				appname=content[i][2]
            					}else{
	            					status=content[i][k].status;
	            					if(status=='0'){
										strHtml="<a class='vl' style='color:red;' href='javascript:void(0);' status_v='1' avalue="+content[i][k].branchid+","+content[i][k].id+">禁用</a>";
									}else{
										strHtml="<a class='vl' href='javascript:void(0);' status_v='0' avalue="+content[i][k].branchid+","+content[i][k].id+">审核通过</a>";
									}
	            					var str= "<tr><td>"+content[i][k].id+"</td>"
	            						  +"<td>"+appname+"</td>"
	            						  +"<td>"+username+"</td>"
	            						  +"<td>"+formatDate(new Date(content[i][k].creattime))+"</td>"
	            						  +"<td>"+content[i][k].key+"</td>"
	            						  +"<td>"+content[i][k].name+"</td>"
	            						  +"<td>"+strHtml+"</td>"
	            						  +"</tr>";
            					}
            				}
            			}
            			$("#tab").append(str);
            		}
            	},
            	error:function(){
            		$("#tsdiv").show();
            		$("#pager").hide();
            		$("#tTab").hide();
            	}
   			});
   		}
   		$(function(){
   			//分页方法
   			PageClick(1);
   			//为表格添加的内容绑定点击事件
   			$("#tab").on('click','.vl',function(){
   				var me = this;
   				var values=$(me).attr("avalue");
				var value = values.split(",");
				var status_value=$(me).attr("status_v");
				$.ajax({
					url:'mexamine/update',
					type:'post',
					data:{branch_id:value[0],id:value[1],status:status_value},
					dataType:'json',
					success:function(JR){
						if(JR==true){	
							var txt=$(me).text();
							if(txt=="禁用"){
								$(me).attr("status_v","0");
								$(me).text("审核通过");
								$(me).css("color","");
							}else{
								$(me).text("禁用");
								$(me).attr("status_v","1");
								$(me).css("color","red");
							}
						}			
					}
				});
			});
			//监控搜索文本框  
			$("#search").bind("input propertychange",function(){
				type=$('#op').val();
				search=$(this).val();
				PageClick(1);
			});
			
   		});
   		function formatDate(now){     
			var year=now.getFullYear();     
			var month=now.getMonth()+1;     
			var date=now.getDate();     
			var hour=now.getHours();     
			var minute=now.getMinutes();     
			var second=now.getSeconds();     
			return year+"/"+month+"/"+date+" "+hour+":"+minute+":"+second;     
		}
    </script>
 </body>
</html>
